<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Go Ethereum Guide</title>
    <link rel="icon" type="image/png" href="../static/images/favicon.png" />

    <link href="../static/styles/bootstrap.min.css" rel="stylesheet" />
    <link href="../static/styles/flatly.min.css" rel="stylesheet" />
    <link href="../static/styles/font-awesome.min.css" rel="stylesheet" />
    <link href="../static/styles/highlight.min.css" rel="stylesheet" />

    <link href="../static/styles/custom/common.css" rel="stylesheet" />

    <script src="../static/scripts/jquery.min.js"></script>
    <script src="../static/scripts/bootstrap.min.js"></script>
    <script src="../static/scripts/moment.min.js"></script>
    <script src="../static/scripts/marked.min.js"></script>
    <script src="../static/scripts/emojify.min.js"></script>
    <script src="../static/scripts/highlight.min.js"></script>
    <script src="../static/scripts/highlight-go.min.js"></script>
    <script src="../static/scripts/highlight-java.min.js"></script>
    <script src="../static/scripts/highlight-gradle.min.js"></script>
    <script src="../static/scripts/highlight-swift.min.js"></script>

    <script src="../static/scripts/custom/polyfills.js"></script>
  </head>

  <body>
    <nav class="navbar navbar-default navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="../">Go Ethereum</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <ul class="nav navbar-nav">
            <li><a href="../install/">Install</a></li>
            <li><a href="../downloads/">Downloads</a></li>
            <li class="active"><a href="../guide/">Guide</a></li>
          </ul>
        </div>
      </div>
    </nav>

    <div class="container" style="padding-top: 24px;">
      <div class="row">
        <div class="col-md-3" id="toc" style="padding-top: 16px;"></div>
        <div class="col-md-9" id="content"></div>
      </div>
      <hr/>
      <footer>
        <p>&copy; 2013-2016. The go-ethereum Authors.</p>
      </footer>
    </div>

    <script type="text/javascript">
      // Download the developer guide ToC and convert it into a guide sidebar
      $.ajax({
        url: 'https://raw.githubusercontent.com/wiki/ethereum/go-ethereum/Developer-Guide.md',
        error: function() {
          alert("Failed to load latest release!");
        },
        dataType: 'text',
        success: function(data) {
          // Iterate over all the lines of the sidebar markdown
          var lines = data.split("\n");

          var toc = $("#toc");
          var menu;

          var head;
          for (var i = 0; i < lines.length; i++) {
            // Skip any empty lines
            var line = lines[i].trim();
            if (line == "") {
              continue;
            }
            // If the line is a heading, add a new menu entry
            if (line[0] == "#") {
              while (line.length > 0 && line[0] == "#") {
                line = line.slice(1);
              }
              head = line.trim();
              menu = $("<div class='list-group'></div>").appendTo(toc);
              $("<a href='#' class='list-group-item active'>" + head + "</a>").appendTo(menu);
              continue;
            }
            // Otherwise if the line is a link, add a new entry to the sub-menu
            if (line[0] == "[") {
              var name = /\[(.*)\]/g.exec(line)[1];
              var id   = (head + "-" + name).split(" ").join("-");

              var link = /\((.*)\)/g.exec(line)[1];
              link = "https://raw.githubusercontent.com/wiki/" + link.slice("https://github.com/".length).replace("wiki/", "") + ".md";

              var item = $("<a id='menu-" + id + "' href='#" + id + "' class='list-group-item'>" + name + "</a>").appendTo(menu);
              $(item).click(function(id, head, name, link) {
                return function() {
                  $.ajax({
                    url: link,
                    error: function() {
                      $('#content').html("<div class='alert alert-dismissible alert-danger'>Failed to load guide page \"" + name + "\". Please report this issue on our <a href='https://github.com/ethereum/go-ethereum/issues' class='alert-link'>bug tracker</a>. Thank you!</div>");
                    },
                    dataType: 'text',
                    success: function(data) {
                      // Load the wiki page content into the current page
                      $('#content').html("<h1>" + head + ": " + name + "</h1>" + marked(data));
                      emojify.setConfig({img_dir: '../static/images/emoji'});
                      emojify.run(document.getElementById('content'));

                      // Run the syntax highlighter on all code blocks
                      $('pre code').each(function(i, block) {
                        hljs.highlightBlock(block);
                      });
                    }
                  });
                };
              }(id, head, name, link));
            }
          }
          // Menu constructed, load the specified entry, or first if non existent
          if (window.location.hash.length > 1) {
            $('#menu-' + window.location.hash.split('#')[1])[0].click();
          } else {
            $(toc.children()[0]).children()[1].click();
          }
        }
      });
    </script>
  </body>
</html>
